﻿@model S4Store.Models.AfterSaleReport.AfterSaleReportServiceAdvisorModel
@{
    Layout = null;
    ViewBag.Title = "SaleTimeRate";
}
<script type="text/javascript">
    $(function () {
        var $c = $("#myContentArea");
        var count = $("#myContentArea").find("table td").has(".value").size();
        var right = parseInt($("#right").css("width").replace("px", "")) - 20;
        if (count * 190 + 70 >= right) {
            $c.width(count * 190 + 70);
        }
    });
</script>
<div style="height: 100%; width: 100%; overflow: auto;">
<div id="myContentArea" style="overflow:hidden">
@Html.Action("ReportBar", "Common", Model.BarModel)
<div style="position:relative; width:100%">
  <div class="pagetitle">各人员事故车产值差异</div>
    @{
        List<dynamic> list = new List<dynamic>();
        
        var query = from s in Model.SADayDatas
                    group s by s.EmployeeId into g
                    select new { g, 车型 = g.FirstOrDefault().Employee.Name };
        foreach(var item in query)
        {
            list.Add(new
            {
                时间进度=ViewBag.时间进度,

                目标事故车产值 = Model.MonthTarget.Where(o => o.EmployeeId == item.g.Key).Sum(o => o.BYSGCCZMB_AccidentCarValueTarget),

                应事故车产值 = Model.MonthTarget.Where(o => o.EmployeeId == item.g.Key).Sum(o => o.BYSGCCZMB_AccidentCarValueTarget) * ViewBag.时间进度,

                实际事故车产值 = item.g.Sum(o => o.SGCCZ_AccidentCarValue),

                车型 = item.车型,
                
                用户ID=item.g.Key
            });
        }

        var chartwidth = query.Count() * 190;
        var tbwidth = query.Count() * 180;

        S4Store.Models.Chart.Column ChartModel = new S4Store.Models.Chart.Column();
        ChartModel.Colors = new List<string> { S4Store.Models.Chart.Color.Green, S4Store.Models.Chart.Color.Blue };
        //ChartModel.Name = "登记客户";
        ChartModel.YAxis = "比例(%)";
        //ChartModel.Width = chartwidth;
        //ChartModel.Height = 300;
        foreach(var item in list)
        {
            ChartModel.XAxis.Add(item.车型);
        }

        S4Store.Models.Chart.ChartSeries series1 = new S4Store.Models.Chart.ChartSeries();
        series1.Name = "目标事故车产值进度";
        foreach(var item in list)
        {
            series1.Data.Add(item.时间进度*100);
        }
        ChartModel.Serieses.Add(series1);


        S4Store.Models.Chart.ChartSeries series2 = new S4Store.Models.Chart.ChartSeries();
        series2.Name = "实际事故车产值进度";
        foreach(var item in list)
        {
            series2.Data.Add(item.目标事故车产值 == 0 ? 0 : ((decimal)item.实际事故车产值 / (decimal)item.目标事故车产值) * 100);
        }
        ChartModel.Serieses.Add(series2);
    
    
        @Html.Partial("../Chart/Column", ChartModel)
        <div style=" margin-left:70px; overflow:hidden">
        <table style="width:100%">
            <tr>
                @foreach(var item in list)
                {
                    var 目标事故车产值进度 = Math.Round(item.时间进度 * 100, 1, MidpointRounding.AwayFromZero);
                    var 实际事故车产值进度 = item.目标事故车产值 == 0 ? 0 : Math.Round(((decimal)item.实际事故车产值 / (decimal)item.目标事故车产值) * 100, 1, MidpointRounding.AwayFromZero);
                    var 应时产值 = Math.Round(item.应事故车产值, 0, MidpointRounding.AwayFromZero);
                <td align="center" width="30">
                @if (实际事故车产值进度 < 目标事故车产值进度)
                {
                    <a class="specialRed" href="@Url.Action("AccidentCar_SellerCZKPI", new { sellerid = item.用户ID })" target="navtab" title="事故车产值差异">
                        <div class="value">@(实际事故车产值进度 - 目标事故车产值进度)%</div>
                        <div class="rt">实际产值：@item.实际事故车产值</div>
                        <div class="rb">应时产值：@应时产值</div>
                    </a>
                }
                else
                {
                    <a class="specialGreen" href="@Url.Action("AccidentCar_SellerCZKPI", new { sellerid = item.用户ID })" target="navtab" title="事故车产值差异">
                        <div class="value">@(实际事故车产值进度 - 目标事故车产值进度)%</div>
                        <div class="rt">实际产值：@item.实际事故车产值</div>
                        <div class="rb">应时产值：@应时产值</div>
                    </a>
                }

                </td>
                    }
            </tr>
        </table>
        </div>
        
        }
    
</div>
</div>
</div>